//
//  CatogryArtifactDetailViewController.m
//  project
//
//  Created by lanou on 15/11/3.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "CatogryArtifactDetailViewController.h"
#import "PKRequestManager.h"
#import "UMSocial.h"

@interface CatogryArtifactDetailViewController ()

//创建选礼神器的点击界面
@property(nonatomic,strong)UIWebView *artifactDetailView;
//定义一个字符串，接收上一个界面的id
@property(nonatomic,strong)NSString *str;

@end

@implementation CatogryArtifactDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //添加navigationItem
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake((kWidth - 40) / 2, 10, 40, 20)];
    titleLabel.text = @"礼品详情";
    titleLabel.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = titleLabel;
    
    //添加一个navigationBarButtonItem
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"share"] style:(UIBarButtonItemStylePlain) target:self action:@selector(share:)];
    
    _artifactDetailView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
    _artifactDetailView.backgroundColor = [UIColor whiteColor];
    _str = [NSString stringWithFormat:@"%@",self.model.idd];
    [self.view addSubview:_artifactDetailView];
    
    [self requestData];
}

//给navigationBarButton
-(void)share:(UIBarButtonItem *)sender
{
    [UMSocialSnsService presentSnsIconSheetView:self appKey:@"563b243d67e58e950e0021e0" shareText:self.model.name shareImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.model.cover_image_url]]]shareToSnsNames:[NSArray arrayWithObjects:UMShareToDouban,UMShareToSina,UMShareToRenren,UMShareToTumblr,nil] delegate:self];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//数据解析
-(void)requestData
{
    NSMutableDictionary *parDic = [NSMutableDictionary dictionary];
    
    [PKRequestManager requestWithTypeP:GET urlString:[NSString stringWithFormat:@"http://api.liwushuo.com/v2/items/%@",_str] parDic:parDic finish:^(NSData *data) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
        NSDictionary *dict = dic[@"data"];
        NSString *string = dict[@"url"];
        NSURLRequest *request = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:string]];
        [_artifactDetailView loadRequest:request];
        
    } error:^(NSError *error) {
        NSLog(@"数据请求失败");
    }];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
